package com.shine.chemicalWholeProcessSystem.ui.fragment;

import android.Manifest;
import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.shine.chemicalWholeProcessSystem.BR;
import com.shine.chemicalWholeProcessSystem.R;
import com.shine.chemicalWholeProcessSystem.app.GlideShapeImageLoader;
import com.shine.chemicalWholeProcessSystem.base.BaseFragment;
import com.shine.chemicalWholeProcessSystem.bean.RiskManagementBean;
import com.shine.chemicalWholeProcessSystem.databinding.FragmentHomeBinding;
import com.shine.chemicalWholeProcessSystem.ui.adapter.MainMessageAdapter;
import com.shine.chemicalWholeProcessSystem.ui.fragment.viewModel.HomeViewModel;
import com.shine.chemicalWholeProcessSystem.ui.hiddenTroubleInvestigation.HiddenTroubleInvestigationListActivity;
import com.shine.chemicalWholeProcessSystem.ui.patrolManagement.PatrolManagementListActivity;
import com.shine.chemicalWholeProcessSystem.ui.riskAssessment.RiskAssessmentListActivity;
import com.shine.chemicalWholeProcessSystem.ui.riskManagement.RiskManagementListActivity;
import com.shine.chemicalWholeProcessSystem.ui.scoreQuery.ScoreQueryListActivity;
import com.shine.chemicalWholeProcessSystem.ui.search.SearchActivity;
import com.shine.chemicalWholeProcessSystem.ui.video.VideoSurveillanceActivity;
import com.shine.chemicalWholeProcessSystem.utils.ScreenUtils;
import com.shine.chemicalWholeProcessSystem.view.chart.BarAndLineChart;
import com.shine.chemicalWholeProcessSystem.view.chart.HorizontalLineChart;
import com.shine.chemicalWholeProcessSystem.view.chart.ManyHorizontalLineChart;
import com.shine.chemicalWholeProcessSystem.view.chart.RingChart;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.functions.Consumer;

public class HomeFragment extends BaseFragment<FragmentHomeBinding, HomeViewModel> {
    private MainMessageAdapter mainMessageAdapter;

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_home;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public HomeViewModel initViewModel() {
        return new HomeViewModel(getActivity());
    }

    @SuppressLint("CheckResult")
    @Override
    public void initData() {
        super.initData();

        View view = binding.statusBar;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            ViewGroup.LayoutParams params = view.getLayoutParams();
            params.height = ScreenUtils.getStatusBarHeight(view.getContext());
            view.setLayoutParams(params);
        }

        binding.advertBanner.setImageLoader(new GlideShapeImageLoader());
        List<Object> imgList = new ArrayList<>();
        imgList.add(R.mipmap.banner);
        imgList.add("https://t7.baidu.com/it/u=1595072465,3644073269&fm=193&f=GIF");
        imgList.add("https://t7.baidu.com/it/u=4198287529,2774471735&fm=193&f=GIF");
        binding.advertBanner.setImages(imgList);
        binding.advertBanner.start();

        binding.advertBanner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {

            }
        });

        binding.riskManagement.setOnClickListener(this);
        binding.hiddenTroubleInvestigation.setOnClickListener(this);
        binding.riskAssessment.setOnClickListener(this);
        binding.patrolManagement.setOnClickListener(this);
        binding.scoreQuery.setOnClickListener(this);

        mainMessageAdapter = new MainMessageAdapter(binding.recyclerView, R.layout.item_main_message);
        binding.recyclerView.setAdapter(mainMessageAdapter);

        List<String> dataList = new ArrayList<>();
        dataList.add("");
        dataList.add("");
        dataList.add("");
        dataList.add("");
        dataList.add("");
        mainMessageAdapter.addNewData(dataList);

        RxPermissions mRxPermission = new RxPermissions(getActivity());
        mRxPermission.request(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE
                , Manifest.permission.CAMERA)
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean aBoolean) throws Exception {
                        if (aBoolean) {

                        } else {
                        }
                    }
                });

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.riskManagement:
                switchActivity(RiskManagementListActivity.class);
                break;
            case R.id.hiddenTroubleInvestigation:
                switchActivity(HiddenTroubleInvestigationListActivity.class);
                break;
            case R.id.riskAssessment:
                switchActivity(RiskAssessmentListActivity.class);
                break;
            case R.id.patrolManagement:
                switchActivity(PatrolManagementListActivity.class);
                break;
            case R.id.scoreQuery:
                switchActivity(ScoreQueryListActivity.class);
                break;
            default:
                break;
        }

    }
}